[id].vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <div>
  3. <!-- 页面头部 -->
  4. <TopicHead></TopicHead>
  5. <!-- 商圈详情 -->
  6. <div class="topicInfoBox">
  7. <div class="inner">
  8. <!-- 详情头部 -->
  9. <div class="infoHead">
  10. <div class="left">
  11. <div class="userInfo left">
  12. <el-badge value="楼主" class="item" type="warning">
  13. <img v-if='dataInfo.avatar' :src="dataInfo.avatar" alt="">
  14. <img v-else src='../../static/topic/Rectangle.png' alt="">
  15. </el-badge>
  16. <span>{{ dataInfo.nickname }}</span>
  17. </div>
  18. <div class="headContent left">
  19. <h2>{{ dataInfo.title }}</h2>
  20. <p v-show="dataInfo.group_name">
  21. 群聊:
  22. <span>{{ dataInfo.group_name }}</span>
  23. <button @click="joinGroup">加入群聊</button>
  24. </p>
  25. </div>
  26. </div>
  27. <div class="right">
  28. <div class="one" v-if="dataInfo.type == 1">科研</div>
  29. <div class="two" v-else-if="dataInfo.type == 2">维权</div>
  30. <div class="three" v-else-if="dataInfo.type == 3">讨论</div>
  31. <p>{{ dataInfo.updated_at }}</p>
  32. </div>
  33. </div>
  34. <!-- 详情页 文本+图片 -->
  35. <div class="infoContent" v-show="dataInfo.content">
  36. <div v-html="dataInfo.content"></div>
  37. </div>
  38. <div class="infoContent1" v-show="!dataInfo.content">
  39. <img src="../../static/topic/Document_empty.png" alt="">
  40. <span>可以看看大家的互动哦~</span>
  41. </div>
  42. <!-- 详情页评论 -->
  43. <div class="comment">
  44. <h3>评论</h3>
  45. <div class="commentList" v-for="item in replyList" v-show="page_total != 0">
  46. <div class="left">
  47. <img v-if='item.avatar' :src="item.avatar" alt="">
  48. <img v-else src='../../static/topic/Rectangle.png' alt="">
  49. <span class="name">{{ item.nickname }} : </span>
  50. <span class="context">{{ item.content }}</span>
  51. </div>
  52. <div class="right">
  53. <span class="time">{{ item.created_at }}</span>
  54. <!-- <span>回复</span> -->
  55. </div>
  56. </div>
  57. <div class="comment_empty" v-show="page_total == 0">
  58. <img src="../../static/topic/message_empty.png" alt="">
  59. <span>暂无评论</span>
  60. </div>
  61. </div>
  62. <!-- 分页 -->
  63. <div class="paginationBox" v-show="page_total != 0">
  64. <el-pagination background layout="prev, pager, next" :total="page_total" prev-text="上一页"
  65. next-text="下一页" :default-page-size="pageSize" @change="changePage" />
  66. </div>
  67. </div>
  68. </div>
  69. <div class="message">
  70. <div class="inner">
  71. <input v-model="content" placeholder="快来回复吧~" type="text" class="messageInput">
  72. <button class="btn" @click="addReply">确定</button>
  73. </div>
  74. </div>
  75. <!-- 页面底部 -->
  76. <!-- <HomeFoot></HomeFoot> -->
  77. <AdvertisingFoot></AdvertisingFoot>
  78. </div>
  79. </template>
  80. <script setup>
  81. //1.引用模块 start ---------------------------------------->
  82. //使用ref和reactive动态变量
  83. import { ref, reactive, onMounted } from 'vue'
  84. import { useRoute } from 'vue-router';
  85. //使用官方ssr请求模块
  86. import { useNuxtApp, useFetch } from '#app'
  87. //使用element-plus组件
  88. import { ElPagination, ElBadge, ElInput, ElMessage, ElMessageBox } from 'element-plus';
  89. // axios请求
  90. const nuxtApp = useNuxtApp();
  91. const axios = nuxtApp.$axios;
  92. //1.引用模块 end ---------------------------------------->
  93. //2.页面数据 start ---------------------------------------->
  94. const dataInfo = ref({})
  95. const groupId = useState("groupId", () => '')
  96. const replyList = useState("replyList", () => []) //评论列表
  97. //分页
  98. const page = ref(1)
  99. const pageSize = ref(5)
  100. let page_total = ref(0)
  101. const content = ref('')
  102. //2.页面数据 end ---------------------------------------->
  103. //3.获取商圈详情 start ---------------------------------------->
  104. const route = useRoute();
  105. const id = route.params.id; // 获取传递的 id 参数
  106. //页码发生改变
  107. const changePage = (val) => {
  108. console.log(val);
  109. page.value = val
  110. getTopicReply()
  111. }
  112. // 商圈信息
  113. const getTopicInfo = () => {
  114. let data = new FormData()
  115. data.append('id', id)
  116. axios.post('chat/getTopicInfo', data).then(res => {
  117. console.log('商圈信息', res);
  118. dataInfo.value = res.data
  119. groupId.value = res.data.group_id
  120. console.log(groupId.value);
  121. })
  122. }
  123. // 回复商圈 列表
  124. const getTopicReply = () => {
  125. let data = new FormData()
  126. data.append('id', id)
  127. data.append('page', page.value)
  128. data.append('page_size', pageSize.value)
  129. axios.post('chat/getTopicReply', data).then(res => {
  130. console.log('回复商圈列表 ', res);
  131. replyList.value = res.data.data
  132. // page_total.value = res.data.total
  133. // replyList.value = res.data.data.sort((a, b) => {
  134. // const dateA = new Date(a.created_at);
  135. // const dateB = new Date(b.created_at);
  136. // return dateB - dateA; // 降序排序
  137. // });
  138. // replyList.value = res.data.data.sort((a, b) => {
  139. // return new Date(b.created_at) - new Date(a.created_at);
  140. // });
  141. page_total.value = res.data.total
  142. console.log("replyList", replyList);
  143. })
  144. }
  145. onMounted(() => {
  146. getTopicInfo(); //商圈信息
  147. getTopicReply(); //回复商圈列表
  148. })
  149. //加入群聊
  150. const joinGroup = () => {
  151. ElMessageBox.confirm(
  152. '加入群聊后,页面跳转至后台群聊页面',
  153. '是否加入群聊?',
  154. {
  155. confirmButtonText: '是',
  156. cancelButtonText: '否',
  157. center: true,
  158. }
  159. ).then(() => {
  160. console.log('groupId.value', groupId.value);
  161. let data = new FormData()
  162. data.append('group_id', groupId.value)
  163. axios.post('chat/joinGroup', data).then(res => {
  164. console.log('加入群聊 ', res);
  165. if (res.code == 0 && res.message !== '已加入群') {
  166. ElMessage.error(res.message)
  167. } else if (res.code == 0 && res.message == '已加入群') {
  168. ElMessage({
  169. message: res.message,
  170. type: 'success',
  171. })
  172. setTimeout(() => {
  173. // window.location.href = ("http://adminpre.bjzxtw.org.cn/#/hall")
  174. window.open('http://adminpre.bjzxtw.org.cn/#/hall', '_blank');
  175. }, 1000)
  176. } else if (res.code == 200) {
  177. ElMessage({
  178. message: '加入成功',
  179. type: 'success',
  180. })
  181. setTimeout(() => {
  182. // window.location.href = ("http://adminpre.bjzxtw.org.cn/#/hall")
  183. window.open('http://adminpre.bjzxtw.org.cn/#/hall', '_blank');
  184. }, 1000)
  185. }
  186. })
  187. }).catch(() => {
  188. ElMessage({
  189. type: 'error',
  190. message: '已取消',
  191. })
  192. })
  193. }
  194. // 回复商圈
  195. const addReply = () => {
  196. let data = new FormData()
  197. data.append('id', id)
  198. data.append('content', content.value)
  199. axios.post('chat/addReply', data).then(res => {
  200. console.log('回复商圈 ', res);
  201. if (res.code == 0) {
  202. ElMessage.error(res.message)
  203. getTopicReply();
  204. } else if (res.code == 200) {
  205. ElMessage({
  206. message: '回复成功',
  207. type: 'success',
  208. })
  209. content.value = ''
  210. getTopicReply();
  211. }
  212. })
  213. }
  214. //3.获取商圈详情 end ---------------------------------------->
  215. </script>
  216. <style lang="less" scoped>
  217. .topicInfoBox {
  218. .inner {
  219. width: 1200px;
  220. margin: 0 auto;
  221. //信息头部
  222. .infoHead {
  223. height: 200px;
  224. padding: 65px 0 60px 40px;
  225. border-bottom: 1px solid rgba(0, 0, 0, 0.10);
  226. box-sizing: border-box;
  227. >.left {
  228. .userInfo {
  229. margin-right: 90px;
  230. .item {
  231. margin-top: -5px;
  232. margin-right: -5px;
  233. :deep(.el-badge__content.is-fixed) {
  234. position: absolute;
  235. right: calc(1px + var(--el-badge-size) / 2);
  236. top: 0;
  237. transform: translateY(-31%) translateX(79%);
  238. z-index: var(--el-index-normal);
  239. }
  240. img {
  241. width: 66px;
  242. height: 66px;
  243. vertical-align: middle;
  244. border-radius: 50%;
  245. }
  246. }
  247. span {
  248. margin-left: 15px;
  249. font-family: Microsoft YaHei, Microsoft YaHei;
  250. font-weight: 400;
  251. font-size: 18px;
  252. color: #333333;
  253. }
  254. }
  255. .headContent {
  256. h2 {
  257. font-family: Microsoft YaHei, Microsoft YaHei;
  258. font-weight: bold;
  259. font-size: 20px;
  260. color: #333333;
  261. margin-bottom: 26px;
  262. }
  263. >p {
  264. font-family: Microsoft YaHei, Microsoft YaHei;
  265. font-weight: 400;
  266. font-size: 16px;
  267. color: #333333;
  268. button {
  269. width: 86px;
  270. height: 32px;
  271. background-color: #028e21;
  272. color: #fff;
  273. border: none;
  274. margin-left: 100px;
  275. }
  276. }
  277. }
  278. }
  279. >.right {
  280. position: relative;
  281. div {
  282. position: absolute;
  283. right: 0;
  284. top: 0;
  285. width: 71px;
  286. height: 32px;
  287. line-height: 32px;
  288. text-align: center;
  289. background-color: #d9f0d6;
  290. margin-bottom: 29px;
  291. font-family: Microsoft YaHei, Microsoft YaHei;
  292. font-weight: 400;
  293. font-size: 16px;
  294. color: #33B023;
  295. }
  296. .one {
  297. color: #FFAA33;
  298. background-color: #fbebd5;
  299. }
  300. .two {
  301. color: #33B023;
  302. background-color: #d5ecd2;
  303. }
  304. .three {
  305. color: #666;
  306. background-color: #ebebeb;
  307. }
  308. p {
  309. width: 150px;
  310. text-align: right;
  311. position: absolute;
  312. top: 62px;
  313. right: 0;
  314. }
  315. }
  316. }
  317. // 有详情信息
  318. .infoContent {
  319. overflow: hidden;
  320. padding: 40px 46px;
  321. font-family: Microsoft YaHei, Microsoft YaHei;
  322. font-size: 20px;
  323. line-height: 40px;
  324. }
  325. //没有详情信息
  326. .comment_empty,
  327. .infoContent1 {
  328. height: 300px;
  329. line-height: 260px;
  330. text-align: center;
  331. img {
  332. width: 78px;
  333. height: 78px;
  334. vertical-align: -25px;
  335. vertical-align: middle;
  336. margin-right: 20px;
  337. }
  338. span {
  339. font-family: Microsoft YaHei, Microsoft YaHei;
  340. font-weight: bold;
  341. font-size: 26px;
  342. color: #CCCCCC;
  343. }
  344. }
  345. //评论
  346. .comment {
  347. h3 {
  348. height: 100px;
  349. padding-top: 30px;
  350. box-sizing: border-box;
  351. border-bottom: 1px solid #E1E1E1;
  352. font-family: Microsoft YaHei, Microsoft YaHei;
  353. font-weight: 400;
  354. font-size: 22px;
  355. color: #000000;
  356. }
  357. .commentList {
  358. height: 112px;
  359. border: 1px solid #E1E1E1;
  360. background-color: #fafafa;
  361. margin-top: 20px;
  362. padding: 30px 30px;
  363. box-sizing: border-box;
  364. .left {
  365. img {
  366. width: 52px;
  367. height: 52px;
  368. border-radius: 50%;
  369. vertical-align: middle;
  370. margin-right: 15px;
  371. }
  372. .name {
  373. font-family: Microsoft YaHei, Microsoft YaHei;
  374. font-weight: 400;
  375. font-size: 16px;
  376. color: #333333;
  377. margin-right: 30px;
  378. }
  379. .context {
  380. font-family: Microsoft YaHei, Microsoft YaHei;
  381. font-weight: bold;
  382. font-size: 16px;
  383. color: #333333;
  384. }
  385. }
  386. .right {
  387. padding: 14px 0;
  388. .time {
  389. font-family: Microsoft YaHei, Microsoft YaHei;
  390. font-weight: 400;
  391. font-size: 16px;
  392. color: #999999;
  393. margin-right: 30px;
  394. }
  395. span {
  396. font-family: Microsoft YaHei, Microsoft YaHei;
  397. font-weight: 400;
  398. font-size: 16px;
  399. color: #333333;
  400. }
  401. }
  402. }
  403. // .comment_empty {
  404. // height: 200px;
  405. // line-height: 200px;
  406. // text-align: center;
  407. // img {
  408. // width: 78px;
  409. // height: 78px;
  410. // vertical-align: -25px;
  411. // margin-right: 20px;
  412. // }
  413. // span {
  414. // font-family: Microsoft YaHei, Microsoft YaHei;
  415. // font-weight: bold;
  416. // font-size: 26px;
  417. // color: #CCCCCC;
  418. // }
  419. // }
  420. }
  421. }
  422. }
  423. //评论回复
  424. .message {
  425. width: 100%;
  426. height: 145px;
  427. line-height: 145px;
  428. background-color: #ecf5ee;
  429. .inner {
  430. .messageInput {
  431. width: 1049px;
  432. height: 67px;
  433. outline: none;
  434. border: 1px solid #E1E1E1;
  435. background-color: #fafafa;
  436. font-family: Microsoft YaHei, Microsoft YaHei;
  437. font-weight: 400;
  438. font-size: 18px;
  439. color: #666;
  440. padding-left: 20px;
  441. box-sizing: border-box;
  442. }
  443. .btn {
  444. width: 115px;
  445. height: 40px;
  446. border: none;
  447. background-color: #028e21;
  448. color: #fff;
  449. border-radius: 6px;
  450. margin-left: 36px;
  451. font-family: Microsoft YaHei, Microsoft YaHei;
  452. font-weight: 400;
  453. font-size: 16px;
  454. }
  455. }
  456. }
  457. //分页
  458. .paginationBox {
  459. display: flex;
  460. justify-content: center;
  461. margin-top: 60px;
  462. margin-bottom: 90px;
  463. // 鼠标移入后字体颜色
  464. :deep(.el-pagination:hover) {
  465. color: #139609;
  466. }
  467. :deep(.el-pagination.is-background .btn-next),
  468. :deep(.el-pagination.is-background .btn-prev) {
  469. width: 70px;
  470. height: 34px;
  471. margin: 0px 10px;
  472. border-radius: 4px;
  473. }
  474. :deep(.el-pagination.is-background .el-pager li) {
  475. margin: 0px 10px;
  476. width: 38px;
  477. height: 34px;
  478. border-radius: 4px;
  479. }
  480. :deep(.el-pagination.is-background .btn-next.is-active),
  481. :deep(.el-pagination.is-background .btn-prev.is-active),
  482. :deep(.el-pagination.is-background .el-pager li.is-active) {
  483. background-color: #028e21;
  484. color: #fff;
  485. }
  486. }
  487. </style>